<?php

RegisterPlugin('light_blog', 'ActivePlugin_light_blog');

function ActivePlugin_light_blog()
{
    global $zbp;
    $zbp->LoadLanguage('theme', 'light_blog');
    $zbp->lang['msg']['first_button'] = '&lt;&lt;';
    $zbp->lang['msg']['prev_button'] = '&lt;';
    $zbp->lang['msg']['next_button'] = '&gt;';
    $zbp->lang['msg']['last_button'] = '&gt;&gt;';
    $zbp->lang['msg']['sidebar'] = '首页侧栏';
    $zbp->lang['msg']['sidebar2'] = '分类列表侧栏';
    $zbp->lang['msg']['sidebar3'] = '文章页侧栏';
    $zbp->lang['msg']['sidebar4'] = '单页侧栏';
    $zbp->lang['msg']['sidebar5'] = '搜索列表侧栏';
    $zbp->lang['msg']['sidebar6'] = '其他列表侧栏';
    Add_Filter_Plugin('Filter_Plugin_ViewSearch_Begin', 'light_blog_ViewSearch_Begin');
}

function light_blog_ViewSearch_Begin()
{
    global $zbp;
    $zbp->option['ZC_SEARCH_TYPE'] = 'list';
}

// 文章列表缩略图
function light_blog_thumbnail($Source)
{
    global $zbp;
    $temp = mt_rand(1, 20);
    $thumbSrc = '';
    if (ZC_VERSION_COMMIT >= 2800) {
        if ($Source->ImageCount >= 1 && (count($thumbs = $Source->Thumbs(130, 100, 1)) > 0)) {
            $thumb = $thumbs[0];
        } else {
            $thumb = $zbp->host.'zb_users/theme/'.$zbp->theme.'/style/random/'.$temp.'.jpg';
        }
    } else {
        $pattern = "/<img[^>]*src=\"([^\"]+\.(gif|jpg|png))\"[^>]*>/";
        $content = $Source->Content;
        preg_match_all($pattern, $content, $matchContent);
        if (isset($matchContent[1][0])) {
            $thumb = $matchContent[1][0];
        } else {
            $thumb = $zbp->host.'zb_users/theme/'.$zbp->theme.'/style/random/'.$temp.'.jpg';
        }
    }
    $thumbSrc = $thumb;

    return $thumbSrc;
}
